package com.midi.wholesale.main;

import java.sql.DriverManager;

import com.mysql.jdbc.*;

public class MysqlConnector {

	// crate a connection to the database
	// change the username and password according to your Database Credentials

	public static Connection getConnection() {
		// System.out.println("MySQL Connect Example.");
		Connection conn = null;

		String url = "jdbc:mysql://127.0.0.1:3306/";
		String dbName = "wholesale?useUnicode=true&characterEncoding=utf8";
		String driver = "com.mysql.jdbc.Driver";
		String userName = "root";
		String password = "";


		try {
			Class.forName(driver).newInstance();
			conn = (Connection) DriverManager.getConnection(url + dbName,
					userName, password);
			System.out.println("Connected to the database");

		} catch (Exception e) {
			System.out.println("Error connecting to database");
			e.printStackTrace();
		}
		return conn;
	}

	// close the connection with Database
	public static void closeConnection(Connection conn) {
		try {
			conn.close();
			System.out.println("Disconnected from database");
		}

		catch (Exception e) {
			// TODO: handle exception
		}

	}

}